<template>
    <div class="login-wrap">

        <div class="ms-login">

            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="0px" class="demo-ruleForm">

                <div class="ms-title ivu-card-head">
                    <p>管理员登录</p>
                </div>
                <el-form-item prop="username" class="ms-ipt">
                    <el-input v-model="ruleForm.username" placeholder="username">
                        <template slot="prepend">账号</template>
                    </el-input>
                </el-form-item>

                <el-form-item prop="password">
                    <el-input type="password" placeholder="password" v-model="ruleForm.password"
                              @keyup.enter.native="submitForm('ruleForm')">
                        <template slot="prepend">密码</template>
                    </el-input>
                </el-form-item>

                <el-form-item v-show="show">
                    <p style="color: red">密码或账号错误！</p>
                </el-form-item>
                <div class="login-btn">
                    <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
                </div>
            </el-form>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                show: false,
                submitFormUrl: 'http://bigdata-oauth.huimeimt.cn/Dataplatform/login',
                ruleForm: {
                    username: '',
                    password: '',
                },
                rules: {
                    username: [
                        {required: true, message: '请输入用户名', trigger: 'blur'}
                    ],
                    password: [
                        {required: true, message: '请输入密码', trigger: 'blur'}
                    ]
                }
            }
        },
        methods: {
            submitForm(formName) {
         /*       this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.$axios.post(this.submitFormUrl, this.ruleForm).then(function (res) {
                            if (res.data == true) {
                                localStorage.setItem('ms_username', this.ruleForm.username);
                                this.$router.push('/');
                            } else {
                                this.show = true
                            }
                        }.bind(this)).catch(function (error) {
                            console.log(error);
                        });

                    } else {
                        return false;
                    }
                });*/

                                this.$refs[formName].validate((valid) => {
                                                    if (valid) {
                                                        localStorage.setItem('ms_username', this.ruleForm.username);
                                                        this.$router.push('/');
                                                    } else {
                                                        console.log('error submit!!');
                                                        return false;
                                                    }
                                });


            },


        }
    }
</script>

<style scoped>
    .login-wrap {
        position: relative;
        width: 100%;
        height: 100%;
        background: url("https://file.iviewui.com/iview-admin/login_bg.jpg");
    }

    .ms-title {
        font-size: 20px;
        font-weight: bold;
    }

    .ms-login {
        position: absolute;
        left: 75%;
        top: 50%;
        width: 300px;
        height: 235px;
        margin: -150px 0 0 -190px;
        padding: 40px;
        border-radius: 5px;
        background: #fff;
    }

    .ms-ipt {
        padding-top: 20px;
    }

    .login-btn {
        text-align: center;
    }

    .login-btn button {
        width: 100%;
        height: 36px;
    }
</style>
